﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Classified.Data;


namespace Classified.Service
{
    public class SeService
    {
        public static string GetSeName(string name)
        {
            if (String.IsNullOrEmpty(name))
                return string.Empty;
            const string okChars = "abcdefghijklmnopqrstuvwxyz1234567890 _-";
            name = name.Trim().ToLowerInvariant();


            var sb = new StringBuilder();
            foreach (var c2 in name.ToCharArray().Select(c => c.ToString()).Where(c2 => okChars.Contains(c2)))
            {
                sb.Append(c2);
            }
            var name2 = sb.ToString();
            name2 = name2.Replace(" ", "-");
            while (name2.Contains("--"))
                name2 = name2.Replace("--", "-");
            while (name2.Contains("__"))
                name2 = name2.Replace("__", "_");
            return (name2);
        }
        public static string GetCurrentCode(int id)
        {
            var _datacontext = new ClassifiedContext();
            var data = _datacontext.Database.SqlQuery<string>("exec GetClassifiedPriceCode @classified='" + id + "'").FirstOrDefault();
            return data;
        }
        public static string RandomString()
        {
            var builder = new StringBuilder();
            var random = new Random();
         
            for (var i = 0; i < 6; i++)
            {
                var ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(ch);
            }

            return builder.ToString().ToLower();
        }


       
    }
}